package net.yla.smartbus.core.constants;

import com.alibaba.fastjson.annotation.JSONType;
import net.yla.smartbus.core.exception.EnumNotFoundException;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 *@author:LiuJie
 *@date:2021/6/16
 *@description:用户权限鉴定枚举
 */
@JSONType(serializeEnumAsJavaBean = true)
public enum UserRoleEnum {

    GROUP_INSERT("/data/group/insert","新增分组",1),
    GROUP_SELECT("/data/group/select","查询分组",4),
    GROUP_UPDATE("/data/group/update","修改分组",2),
    GROUP_DELETE("/data/group/delete","删除分组",3),

    VEHICLE_INSERT("/data/vehicle/insert","新增车辆",1),
    VEHICLE_SELECT("/data/vehicle/select","查询车辆",4),
    VEHICLE_UPDATE("/data/vehicle/update","修改车辆",2),
    VEHICLE_DELETE("/data/vehicle/delete","删除车辆",3),

    VEHICLE_TYPE_INSERT("/data/vehicleType/insert","新增车型",1),
    VEHICLE_TYPE_SELECT("/data/vehicleType/select","查询车型",4),
    VEHICLE_TYPE_UPDATE("/data/vehicleType/update","修改车型",2),
    VEHICLE_TYPE_DELETE("/data/vehicleType/delete","删除车型",3),

    DEVICE_INSERT("/data/device/insert","新增设备",1),
    DEVICE_SELECT("/data/device/select","查询设备",4),
    DEVICE_UPDATE("/data/device/update","修改设备",2),
    DEVICE_DELETE("/data/device/delete","删除设备",3),

    PERSON_INSERT("/data/person/insert","新增人员",1),
    PERSON_SELECT("/data/person/select","查询人员",4),
    PERSON_UPDATE("/data/person/update","修改人员",2),
    PERSON_DELETE("/data/person/delete","删除人员",3),

    AREA_INSERT("/data/area/insert","新增区域",1),
    AREA_SELECT("/data/area/select","查询区域",4),
    AREA_UPDATE("/data/area/update","修改区域",2),
    AREA_DELETE("/data/area/delete","删除区域",3),

    DEPARTMENT_INSERT("/data/department/insert","新增部门",1),
    DEPARTMENT_SELECT("/data/department/select","查询部门",4),
    DEPARTMENT_UPDATE("/data/department/update","修改部门",2),
    DEPARTMENT_DELETE("/data/department/delete","删除部门",3),

    WORK_INSERT("/data/work/insert","新增职务",1),
    WORK_SELECT("/data/work/select","查询职务",4),
    WORK_UPDATE("/data/work/update","修改职务",2),
    WORK_DELETE("/data/work/delete","删除职务",3),

    USER_ACCOUNT_INSERT("/data/user/account/insert","新增账号",1),
    USER_ACCOUNT_SELECT("/data/user/account/select","查询账号",4),
    USER_ACCOUNT_UPDATE("/data/user/account/update","修改账号",2),
    USER_ACCOUNT_DELETE("/data/user/account/delete","删除账号",3),

    USER_ROLE_INSERT("/data/user/role/insert","新增角色",1),
    USER_ROLE_SELECT("/data/user/role/select","查询角色",4),
    USER_ROLE_UPDATE("/data/user/role/update","修改角色",2),
    USER_ROLE_DELETE("/data/user/role/delete","删除角色",3),

    USER_MENU_INSERT("/data/user/menu/insert","新增菜单",1),
    USER_MENU_SELECT("/data/user/menu/select","查询菜单",4),
    USER_MENU_UPDATE("/data/user/menu/update","修改菜单",2),
    USER_MENU_DELETE("/data/user/menu/delete","删除菜单",3),

    LOG_SELECT("/data/log/select","查询日志",4);

    private String code;
    private String desc;
    private int type;

    UserRoleEnum(String code, String desc,int type) {
        this.code = code;
        this.desc = desc;
        this.type = type;
    }


    private static final Map<String, UserRoleEnum> BY_VALUE_MAP = new LinkedHashMap<>();

    static {
        for (UserRoleEnum userRoleEnum : values()) {
            BY_VALUE_MAP.put(userRoleEnum.getCode(), userRoleEnum);
        }
    }

    /**
     * 根据code查询对应的外卖类型枚举
     *
     * @param code dode
     * @return RequestMethodEnum
     * @throws EnumNotFoundException
     */
    public static UserRoleEnum convertCode2Enum(String code) throws EnumNotFoundException {
        if (!BY_VALUE_MAP.containsKey(code)) {
            throw new EnumNotFoundException("枚举对应的code" + code + "不存在");
        }
        return BY_VALUE_MAP.get(code);
    }

    /**
     * 根据枚举name查询对应的外卖类型枚举
     *
     * @param str 枚举的name
     * @return RequestMethodEnum
     * @throws EnumNotFoundException
     */
    public static UserRoleEnum convertStr2Enum(String str) throws EnumNotFoundException {
        try {
            return valueOf(str);
        } catch (Exception e) {
            throw new EnumNotFoundException("枚举对应常量" + str + "不存在");
        }
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int getType() {
         return  type;
    }

    public void setType(int type) {
        this.type = type;
    }
}
